//

// (  )
//

package com.tools.acceleratecore.logic.accelerate.memorydeepoptimizer.impl;

import android.content.Context;
import android.text.TextUtils;
import com.tools.acceleratecore.AccelerateCoreFactory;
import com.tools.acceleratecore.CleanCoreConstant;
import com.tools.acceleratecore.logic.accelerate.memorydeepoptimizer.intf.IMemoryDeepOptimizer;
import com.tools.acceleratecore.logic.accelerate.memorydeepoptimizer.intf.IMemoryDeepOptimizerListener;
import com.tools.acceleratecore.tool.intf.INativeMgr;
import com.tools.acceleratecore.util.UtilInstaller;
import com.tools.acceleratecore.xlib.XLibFactory;
import com.tools.acceleratecore.xlib.util.UtilEnv;
import com.tools.acceleratecore.xlib.xlib.impl.XObserver;
import com.tools.acceleratecore.xlib.xlib.intf.IXThreadTask;
import com.tools.acceleratecore.xlib.xlib.intf.IXThreadTaskListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MemoryDeepOptimizer extends XObserver<IMemoryDeepOptimizerListener> implements IMemoryDeepOptimizer {
    private Context mContext = null;
    private IXThreadTask mIXThreadTaskMemoryDeepOptimizer = null;
    private static final int VALUE_INT_TIMEOUT_DAEMON = 30;
    private static final int VALUE_INT_TIME_DELAY_CALLBACK = 5000;

    public MemoryDeepOptimizer() {
        this.mContext = AccelerateCoreFactory.getApplication();
        this._init();
    }

    private void _init() {
        this.mIXThreadTaskMemoryDeepOptimizer = (IXThreadTask)XLibFactory.getInstance().createInstance(IXThreadTask.class);
    }

    public void startMemoryDeepOptimizeAsyn(final long lMemorySize) {
        this.mIXThreadTaskMemoryDeepOptimizer.start(new IXThreadTaskListener() {
            public void onThreadWork() {
                MemoryDeepOptimizer.this.startMemoryDeepOptimizeSyn(lMemorySize);
            }

            public void onThreadComplete() {
                synchronized(MemoryDeepOptimizer.this.mListListener) {
                    Iterator var3 = MemoryDeepOptimizer.this.getListListener().iterator();

                    while(var3.hasNext()) {
                        IMemoryDeepOptimizerListener listener = (IMemoryDeepOptimizerListener)var3.next();
                        listener.onStartMemoryOptimizeAsynComplete();
                    }

                }
            }
        });
    }

    public void startMemoryDeepOptimizeSyn(long lMemorySize) {
        this.Optimizer(lMemorySize, (String)null);
    }

    public void startMemoryDeepOptimizeAsyn(final long lMemorySize, final String strBroadcastComponent) {
        this.mIXThreadTaskMemoryDeepOptimizer.start(new IXThreadTaskListener() {
            public void onThreadWork() {
                MemoryDeepOptimizer.this.startMemoryDeepOptimizeSyn(lMemorySize, strBroadcastComponent);
            }

            public void onThreadComplete() {
                synchronized(MemoryDeepOptimizer.this.mListListener) {
                    Iterator var3 = MemoryDeepOptimizer.this.getListListener().iterator();

                    while(var3.hasNext()) {
                        IMemoryDeepOptimizerListener listener = (IMemoryDeepOptimizerListener)var3.next();
                        listener.onStartMemoryOptimizeAsynComplete();
                    }

                }
            }
        });
    }

    public void startMemoryDeepOptimizeSyn(long lMemorySize, String strBroadcastComponent) {
        this.Optimizer(lMemorySize, strBroadcastComponent);
    }

    private void Optimizer(long lMemorySize, String strBroadcastComponent) {
        INativeMgr iNativeMgr = (INativeMgr)AccelerateCoreFactory.getInstance().createInstance(INativeMgr.class);
        List<String> listArgv = new ArrayList();
        if(!TextUtils.isEmpty(strBroadcastComponent)) {
            if(AccelerateCoreFactory.getLoadLib() == 2) {
                listArgv.add(UtilInstaller.getPackageOwnLibDirFile(this.mContext, CleanCoreConstant.LIB_EFFICIENT_INTACT_NAME));
            } else {
                listArgv.add(UtilInstaller.getPackageLibDirFile(this.mContext, CleanCoreConstant.LIB_EFFICIENT_INTACT_NAME));
            }

            listArgv.add("-d");
            listArgv.add("-c");
            listArgv.add("4097");
            listArgv.add("-u");
            listArgv.add("30");
            listArgv.add("-v");
            listArgv.add(strBroadcastComponent);
            if(UtilEnv.getAndroidVersion() >= 17) {
                listArgv.add("-w");
                listArgv.add(UtilEnv.getUserSerialNumber(this.mContext));
            }

            iNativeMgr.invokeSyn(listArgv);
        }

        listArgv.clear();
        if(AccelerateCoreFactory.getLoadLib() == 2) {
            listArgv.add(UtilInstaller.getPackageOwnLibDirFile(this.mContext, CleanCoreConstant.LIB_EFFICIENT_INTACT_NAME));
        } else {
            listArgv.add(UtilInstaller.getPackageLibDirFile(this.mContext, CleanCoreConstant.LIB_EFFICIENT_INTACT_NAME));
        }

        listArgv.add("-c");
        listArgv.add("4096");
        listArgv.add("-u");
        listArgv.add("" + lMemorySize);
        if(!TextUtils.isEmpty(strBroadcastComponent)) {
            listArgv.add("-v");
            listArgv.add(strBroadcastComponent);
            if(UtilEnv.getAndroidVersion() >= 17) {
                listArgv.add("-w");
                listArgv.add(UtilEnv.getUserSerialNumber(this.mContext));
            }
        }

        iNativeMgr.invokeSyn(listArgv);

        try {
            Thread.sleep(5000L);
        } catch (Exception var7) {
            var7.printStackTrace();
        }

    }
}
